#include "RenderMgr.h"

void RenderMgr::Init() 
{
	//Create dxgi factory
	HR(CreateDXGIFactory(__uuidof(IDXGIFactory), reinterpret_cast<void**>(&dxgiFactory)));

	//Dont change order
	d3dRender = new D3DRender();
	d3dRender->GetDXGISwapChainPtr(&swapChain);
	d3dRender->GetIDXGIDevicePtr(&dxgiDevice);

	d2dRender = new D2DRender(swapChain, dxgiDevice);

	initalized = true;
}

void RenderMgr::Shutdown() 
{
	ReleaseCOM(dxgiDevice);
	ReleaseCOM(swapChain);

	if(d3dRender != NULL) 
	{
		delete d3dRender;
	}

	if(d2dRender != NULL)
	{
		delete d2dRender;
	}

	initalized = false;
}

bool RenderMgr::IsInitialized()
{
	return initalized;
}

void RenderMgr::Update(const Timer& timer)
{
	
	d3dRender->Update();
	d2dRender->Update();
}

void RenderMgr::Draw()
{	
	d3dRender->Draw();
	d2dRender->Draw();

	swapChain->Present(0, 0);
}

void RenderMgr::OnResize()
{
	d2dRender->ReleaseResizedResources();
	d3dRender->ReleaseResizedResources();

	d3dRender->OnResize();
	d2dRender->OnResize();
}